#!/bin/bash
if [[ "$1" -eq "4" ]]
then
  size=200
elif [[ "$1" -eq "32" ]]
then
  size=500
else
  echo "please input 4 or 32 and write or read"
  exit 1
fi
drive=`lsblk  |grep ${size}G |awk '{print $1}'`
rm -rf ./${1}k_result_${2}
for i in {1..1}
do
echo -n "第${i}次" >> ${1}k_result_${2}
fio -direct=1 -iodepth=128 -rw=rand${2}   -ioengine=libaio -bs=${1}k -size=100G -numjobs=1 -runtime=30  -group_reporting -filename=/dev/${drive}  -name=RandRead_4K_Testing > tmp.txt
if [[ $2 == 'read' ]];then
  iops=`cat tmp.txt |grep iops= |awk '{ print $5 }'`
else
  iops=`cat tmp.txt |grep iops= |awk '{ print $4 }'`
fi
echo -n $iops >> ${1}k_result_${2}
lat=`sed -n '9p' tmp.txt |awk '{print $1 $2 $5}' |cut -f1 -d ","`
echo  -n $lat >> ${1}k_result_${2}
echo "" >> ${1}k_result_${2}
done
rm -rf ./tmp.txt
